package ca.cbc.giscommon.entity;

import com.vividsolutions.jts.geom.Geometry;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "shape")
public class Shape extends BaseEntity implements Cloneable, Serializable {

    private static final long serialVersionUID = 2443180377457385627L;
	private long id;
	private String name;
	private String address;
	private String phone;
	private String routeNumber;
	private ShapeType shapeType;
//	private Geometry theGeom;
	private List<Zone> zones;
	
	public Shape() {}
	
	public Shape(String name, String address, String phone, String routeNumber, Geometry theGeom) {
		this.setName(name);
		this.setAddress(address);
		this.setPhone(phone);
		this.setRouteNumber(routeNumber);
		this.setTheGeom(theGeom);
	}

	@Override
	public Shape clone() throws CloneNotSupportedException {
		return (Shape) super.clone();
	}

	public String getAddress() {
		return address;
	}

	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	public long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getPhone() {
		return phone;
	}
	@Column(name = "route_number")
	public String getRouteNumber() {
		return routeNumber;
	}
	
	@ManyToOne
    @JoinColumn(name = "type_id")
	public ShapeType getShapeType() {
		return shapeType;
	}
	
//	@Column(name = "the_geom")
//	@Type(type = "org.hibernatespatial.GeometryUserType")
//	public Geometry getTheGeom() {
//		return theGeom;
//	}
	
	@ManyToMany
    @JoinTable(name = "shape_zone",
            joinColumns = {@JoinColumn(name = "shape_id")},
            inverseJoinColumns = {@JoinColumn(name = "zone_id")})
	public List<Zone> getZones() {
		return zones;
	}

    public void setAddress(String address) {
		this.address = address;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setPhone(String phone) {
		this.phone = phone;
	}

	public void setRouteNumber(String routeNumber) {
		this.routeNumber = routeNumber;
	}
	
	public void setShapeType(ShapeType shapeType) {
		this.shapeType = shapeType;
	}
	
//	public void setTheGeom(Geometry theGeom) {
//		this.theGeom = theGeom;
//	}
	
    public void setZones(List<Zone> zones) {
		this.zones = zones;
	}
	
	public String toString() {
		return new StringBuffer("Shape {id:").append(id)
				.append(", name:").append(name)
				.append(", address:").append(address)
				.append(", phone:").append(phone)
				.append(", routeNumber:").append(routeNumber)
				.append(", shapeType:").append(shapeType)
				.append(", theGeom:").append(theGeom)
				.append("}")
				.toString();
	}
}
